<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/js/elementui/index.css">
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>
<body>
<div id="app">
    <el-table
            ref="roleTable1"
            :data="users"
            style="width: 100%">
        <el-table-column label="员工编号">
            <template slot-scope="scope">
                <span>{{scope.row.on}}</span>
            </template>
        </el-table-column>
        <el-table-column label="员工ID">
            <template slot-scope="scope">
                <span>{{scope.row.id}}</span>
            </template>
        </el-table-column>
        <el-table-column label="账号">
            <template slot-scope="scope">
                <span style="color: #3a8ee6" @click="loginRolese(scope.row.id)">{{ scope.row.userName}}</span>
            </template>
        </el-table-column>
        <el-table-column label="密码">
            <template slot-scope="scope">
                <span>{{ scope.row.passWord }}</span>
            </template>
        </el-table-column>
        <el-table-column label="真实姓名">
            <template slot-scope="scope">
                <span>{{ scope.row.realName }}</span>
            </template>
        </el-table-column>
        <el-table-column label="业绩">
            <template slot-scope="scope">
                <span>{{scope.row.grade}}</span>
            </template>
        </el-table-column>
        <el-table-column label="性别">
            <template slot-scope="scope">
                <span>{{scope.row.sex}}</span>
            </template>
        </el-table-column>
        <el-table-column label="个人邮箱">
            <template slot-scope="scope">
                <span>{{scope.row.userEmail}}</span>
            </template>
        </el-table-column>
        <el-table-column label="联系方式">
            <template slot-scope="scope">
                <span>{{scope.row.userTel}}</span>
            </template>
        </el-table-column>
        <el-table-column label="入职时间">
            <template slot-scope="scope">
                <span>{{scope.row.entryTime}}</span>
            </template>
        </el-table-column>
        <el-table-column label="员工状态">
            <template slot-scope="scope">
                <span>{{scope.row.status}}</span>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">编辑
                </el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
            background
            layout="prev, pager, next"
            @current-change="loginUser"
            :total="total"
            :current-page="current"
            :page-size="pageSize">
    </el-pagination>
    <el-dialog title="用户信息" :visible.sync="dialogFormVisible" @close="">
        <el-form :model="user">
        <el-form-item label="用户名" :label-width="formLabelWidth">
            <el-input v-model="user.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" :label-width="formLabelWidth">
            <el-input v-model="user.realName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="性别" :label-width="formLabelWidth">
            <el-input v-model="user.sex" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="个人邮箱" :label-width="formLabelWidth">
            <el-input v-model="user.userEmail" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系方式电话" :label-width="formLabelWidth">
            <el-input v-model="user.userTel" autocomplete="off"></el-input>
        </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="abolishUser">取 消</el-button>
            <el-button type="primary" @click="roleUser">确 定</el-button>
        </div>
    </el-dialog>
</div>
<script src="/js/vue/vue.js"></script>
<script src="/js/axios/axios.min.js"></script>
<!-- 引入组件库 -->
<script src="/js/elementui/index.js"></script>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                users: null,
                total: 0,//总条数
                current: 1,//当前条数
                pageSize: 5, //每页条数
                dialogFormVisible: false,
                formLabelWidth: '120 px',
                user: {
                    id: '',
                    userName: '',
                    realName: '',
                    sex:'',
                    userEmail:'',
                    userTel:''

                }


            }
        },
        methods: {
            handleEdit(index, row) {
                console.log(index, row);
                this.user=row
                this.dialogFormVisible = true;
            },
            handleDelete(index, row) {
                console.log(index, row);
                this.open(row)
            },
            loginUser(current) {
                this.current = current;
                //加载用户
                axios.get("/users?current=" + current).then(value => {
                    this.users = value.data.records;
                    this.total = value.data.total;
                    this.pageSize = value.data.size;
                    this.current = value.data.current;
                    console.log(value.data)
                })
            },
            abolishUser(){
                this.dialogFormVisible = false;
                this.loginUser(this.current)
            },
            loginRolese(id){
                axios.get("/userRole/"+id).then(value => {
                    location.href="/usercontrol/user-role.html"
                })

            },
            /*changeCurrent(row) {
                //取消所有的选择效果
                this.$refs.roleTable1.clearSelection();
                //选中当前的行
                this.$refs.roleTable1.toggleRowSelection(row);
                this.loginRolese(row.id)
            },
            //取消全选角色
            selectAll() {
                this.$refs.roleTable.clearSelection();
            },*/
            roleUser(){
               axios.put("/roleuserUpdate",this.user).then(value => {
                   this.dialogFormVisible = false;
                   this.loginUser(this.current)
               })
            },
            open(row) {
                this.$confirm('此操作将永久删除'+row.userName, '是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete("/user/"+row.id).then(value => {
                        this.loginUser(this.current)
                    });
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
        mounted() {
            this.loginUser(1);

        }
    });
</script>
</body>
</html>
